package entity;

public class EStringRegister extends ERegister {
	private String value = "";
	
	public EStringRegister(String name, int address, String dataType,
			String description, String unit) {
		super(name, address, dataType, description, false, unit);
	}

	@Override
	public Object getValue() {
		return value;
	}

	@Override
	public void setValue(byte b0, byte b1, byte b2, byte b3) {
		String registerString = "";
		
		String byteString = Integer.toBinaryString(b3);
		if (byteString.length() > 8) {
			registerString += byteString.substring(byteString.length()-8);
		} else {
			registerString += "00000000".substring(byteString.length()) + byteString;
		}
		byteString = Integer.toBinaryString(b2);
		if (byteString.length() > 8) {
			registerString += byteString.substring(byteString.length()-8);
		} else {
			registerString += "00000000".substring(byteString.length()) + byteString;
		}
		byteString = Integer.toBinaryString(b1);
		if (byteString.length() > 8) {
			registerString += byteString.substring(byteString.length()-8);
		} else {
			registerString += "00000000".substring(byteString.length()) + byteString;
		}
		byteString = Integer.toBinaryString(b0);
		if (byteString.length() > 8) {
			registerString += byteString.substring(byteString.length()-8);
		} else {
			registerString += "00000000".substring(byteString.length()) + byteString;
		}
		
		if (!registerString.equalsIgnoreCase(this.value)) {
			value = registerString;
			
			setChanged();
			notifyObservers(value);
		}
	}
}
